package com.sap.tpcd.policybuilder.policyhandler;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.List;

import org.apache.rampart.policy.RampartPolicyData;
import org.apache.woden.wsdl20.xml.DescriptionElement;
import org.apache.woden.wsdl20.xml.InterfaceOperationElement;
import org.apache.ws.secpolicy.model.AlgorithmSuite;

import com.sap.tpcd.parserengine.wsdlfile.WSDLParser;
import com.sap.tpcd.policybuilder.policymodel.AlgorithmeSuite;
import com.sap.tpcd.policybuilder.policymodel.DataProtection;
import com.sap.tpcd.policybuilder.policymodel.Operation;
import com.sap.tpcd.policybuilder.policymodel.PolicyElement;
import com.sap.tpcd.policybuilder.policymodel.Protocol;

public class DPHandler {

	/**
	 * @param args
	 */
	private InterfaceOperationElement[] Services;
	private String protocol;
	private AlgorithmSuite algoSuite ;
	

	public DPHandler(File file) {
		WSDLParser wsdlParser = new WSDLParser(file);
		this.Services = wsdlParser.getWSDLAction(wsdlParser.getDescElement());
		RampartPolicyData policyData = wsdlParser.getPolicyData(wsdlParser.getDescElement());
		if ((policyData.isAsymmetricBinding())
				|| (policyData.isSymmetricBinding())) {
			this.protocol = "SOAP";
		} else {
			this.protocol = "HTTPS";
		}
		this.algoSuite = policyData.getAlgorithmSuite();
	}
	
//	public static void main(String[] args) {	
//		DPHandler dpCollector = new DPHandler(new File("C:\\Users\\i068988\\Desktop\\wodenExt-eg\\wsdl\\wsdlFile\\test.wsdl"));
//		
//		int index1 = dpCollector.getAlgoSuite().getEncryption().indexOf("#") + 1;
//		String conf =  dpCollector.getAlgoSuite().getEncryption().substring(index1); ;
//		index1 = dpCollector.getAlgoSuite().getDigest().indexOf("#") + 1;
//		String integ = dpCollector.getAlgoSuite().getDigest().substring(index1);
//		System.out.println("Data Protection Policy (" + dpCollector.getServices()[0].getName().getLocalPart() + ", "+ dpCollector.protocol + ", " + conf+", "+ integ+")");
//		
//		Operation service = new Operation();
//		AlgorithmeSuite algorithmeSuite = new AlgorithmeSuite();
//		Protocol protocol = new Protocol();
//		//here we should have a list of a data protections
//		service.setName(dpCollector.getServices()[0].getName().getLocalPart());
//		
//		algorithmeSuite.setName(dpCollector.getAlgoSuite().toString());
//		algorithmeSuite.setConfidentiality(conf);
//		algorithmeSuite.setIntegrity(integ);
//
//		protocol.setName(dpCollector.getProtocol());
//		
//		DataProtection dataProtection = new DataProtection(algorithmeSuite,protocol, service);
//		
//		Operation serviceName = (Operation) dataProtection.getService();
//		AlgorithmeSuite algo = (AlgorithmeSuite) dataProtection.getAlgorithmeSuite();
//		System.out.println(algo.getName()+" conf "+algo.getConfidentiality());
//	}

	public InterfaceOperationElement[] getServices() {
		return Services;
	}

	public void setServices(InterfaceOperationElement[] Services) {
		this.Services = Services;
	}

	public String getProtocol() {
		return protocol;
	}

	public void setProtocol(String protocol) {
		this.protocol = protocol;
	}
	public AlgorithmSuite getAlgoSuite() {
		return algoSuite;
	}

	public void setAlgoSuite(AlgorithmSuite algoSuite) {
		this.algoSuite = algoSuite;
	}

}
